/*
 * Copyright (C) 2018 Donlon.
 *
 * 2018秋季C语言练习题（4）
 * http://10.105.242.83/contest/484/
 *
 * D. 打印方格
 */

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#define PUT_HORIZONTAL_LINE(w)                       \
{                                                    \
    int __tmp = 3 * (w) + 1;                         \
    while (__tmp-- > 0 || (putchar('\n'), 0)) {      \
      putchar('-');                                  \
    }                                                \
}

#define PUT_HORIZONTAL_LATTICES(w)                   \
{                                                    \
    putchar('|');                                    \
    int __tmp = (w);                                 \
    while (__tmp-- > 0 || (putchar('\n'), 0)) {      \
      printf("  |");                                 \
    }                                                \
}

int main() {
  int n;
  scanf("%d", &n);
  int h, w;
  while (n-- > 0) {
    scanf("%d %d", &h, &w);
    PUT_HORIZONTAL_LINE(w)
    while (h-- > 0) {
      PUT_HORIZONTAL_LATTICES(w)
      PUT_HORIZONTAL_LATTICES(w)
      PUT_HORIZONTAL_LINE(w)
    }
  }
}
